#include <cstdio>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
int a[1000001];
map<int,int>mp;
set<int>st;
int main()
{
	int p,n;
	while(scanf("%d",&p)!=EOF)
	{
		mp.clear();
		st.clear();
		for(int i=0;i<p;i++)
		{
			scanf("%d",&a[i]);
			st.insert(a[i]);
		}
		n = st.size();
		int star,end,num,ans;
		star = end = num =0;
		ans = p;
		while(star!=p)
		{
			while(end<p&&num<n)
			{
				if(mp[a[end]]==0)
				{
					num++;
				}
				mp[a[end]]++;
				end++;
			}
			if(num<n) 
			{
				break;
			}
			//printf("%d\n",star);
			ans = min(ans,end-star);
			if(--mp[a[star]]==0)
			{
				
				num--;
			}
			star++;
		}
		printf("%d\n",ans);
	}
} 
